<?php
namespace app\designer;

use cubox;
use cubox\Data;

class App extends cubox\App{
    public function design($name){
        $designerPath =  ROOT.DS.APP.DS.$name.DS.'_setup';
        if (is_dir($designerPath)){
            return true;
        }else{
            return false;
        }
    }

    public function project($name){
        $projectPath = ROOT.DS.APP.DS.$name.DS.'project.php';
        $project = new Data($projectPath);
        $project->read();
        return $project;
    }

    public function designer($name): Data{
        $designerPath = ROOT.DS.APP.DS.$name.DS.'_setup'.DS.'config.php';
        $designer = new Data($designerPath);
        $designer->read();
        return $designer;
    }


    public function getExamplePath(){
        return __DIR__ .DS .'example';
    }

    public function getExpContent($app,$file,$param= array()){
        $path = $this->getExamplePath();

        $content = file_get_contents($path.DS.$file.'.exp');

        $content = str_replace('#app#',$app,$content);

        foreach ($param as $key => $value) {
            $content = str_replace('#'.$key.'#',$value,$content);
        }

        return $content;
    }
}